
cmake_minimum_required(VERSION 3.23)

project(CMakeDemo_i18N)

set(CMAKE_PREFIX_PATH 
${CMAKE_PREFIX_PATH}
"C:/major/development/tools/qt/5.14/install/5.14.2/msvc2015_64"
)

# message("${third_party_root}/commu=${third_party_root}/commu")

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# include(${linguist_cmake})

SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)

set(QT_VERSION 5)
set(REQUIRED_LIBS_QUALIFIED Core Gui Widgets Sql SerialPort)

# CMAKE包查找
find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS_QUALIFIED} REQUIRED)

# 指定源码目录
set(proj_root
	${CMAKE_CURRENT_SOURCE_DIR}/src
)


# 有这些文件需要纳入编译: 不推荐这样用， 应该一个一个文件的手动加入到这里
file(GLOB_RECURSE 
proj_files 
${proj_root}/*.h
${proj_root}/*.cpp
)

# 指定qrc文件
set(project_qrc_file 
${CMAKE_CURRENT_SOURCE_DIR}/qrc/DemoWidget.qrc
)

# -----------------------------------------------
# 创建可执行程序项目
add_executable(${PROJECT_NAME} 
${proj_files}
${widget_files}
${project_qrc_file}
)
# -----------------------------------------------

# ts文件所在路径
set(ALL_TS_ROOT
${CMAKE_CURRENT_SOURCE_DIR}/qrc/i18N
)

# 翻译文件
set(proj_ts_file ${CMAKE_CURRENT_SOURCE_DIR}/qrc/i18N/zh_CN.ts)

# 指定要翻译哪些文件夹
set(project_translate_root
${proj_root}
)

# 添加翻译
CREATE_QM_UPDATE_TS(TARGET_NAME ${PROJECT_NAME} 
TS_ROOT ${ALL_TS_ROOT}
ALL_TS_FILE ${proj_ts_file}
ALL_TRANSLATE_ROOT ${project_translate_root}
)


# 指定头文件搜索路径
target_include_directories(${PROJECT_NAME}
PRIVATE ${proj_root}
PRIVATE ${widget_inc}
)

# 链接Qt库
target_link_libraries(${PROJECT_NAME}
	PRIVATE Qt${QT_VERSION}::Widgets Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui
)

# 如果是windows，设置管理员权限。
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
	set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/level='requireAdministrator'" )
endif()

# 关闭控制台
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
	set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
endif()
